﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using DAL;
using Telerik.Web.UI;

public partial class Baiviet_Xetnghiem : System.Web.UI.UserControl
{
    public static List<XNChoosed> ListChoosed1 = new List<XNChoosed>();
    public static List<XNChoosed> ListChoosed2 = new List<XNChoosed>();

    protected void Page_Load(object sender, EventArgs e)
    {

        if(!Page.IsPostBack){
            ListChoosed1.Clear();
            ListChoosed2.Clear();
        }
            if (ListChoosed1.Count != 0)
            {
                showListChoose1();
            }

            if (ListChoosed2.Count != 0)
            {
                showListChoose2();
            }
    }
    protected void btn_capnhat1_Click(object sender, EventArgs e)
    {
        ListChoosed1.Clear();
        Panel1_in.Controls.Clear();

        IList<RadTreeNode> ListNode = RadTreeView1.GetAllNodes();

        int i = 0;
        foreach (RadTreeNode node in ListNode)
        {

            if (node.Nodes.Count == 0 && node.Checked == true)
            {
                TextBox newTb = new TextBox();
                newTb.ID = "tb_1_" + i.ToString();

                Label newLb = new Label();
                newLb.Text = node.Text;

                XNChoosed newXN = new XNChoosed();
                newXN.Label = newLb;
                newXN.TextBox = newTb;
                newXN.id_madanhmuc = Int32.Parse(node.Value);

                ListChoosed1.Add(newXN);
                i++;
            }
        }

        showListChoose1();
    }

    protected void showListChoose1() {
        Panel1_in.Controls.Add(new LiteralControl("<table>"));
        foreach (XNChoosed xn in ListChoosed1)
        {
            Panel1_in.Controls.Add(new LiteralControl("<tr>"));

            Label SetLb = xn.Label;
            TextBox txtBox = xn.TextBox;

            Panel1_in.Controls.Add(new LiteralControl("<td>"));
            Panel1_in.Controls.Add(SetLb);
            Panel1_in.Controls.Add(new LiteralControl("</td>"));

            Panel1_in.Controls.Add(new LiteralControl("<td>"));
            Panel1_in.Controls.Add(txtBox);
            Panel1_in.Controls.Add(new LiteralControl("</td>"));

            Panel1_in.Controls.Add(new LiteralControl("</tr>"));
        }
        Panel1_in.Controls.Add(new LiteralControl("</table>"));
    }

    protected void showListChoose2() {
        Panel2_in.Controls.Add(new LiteralControl("<table>"));
        foreach (XNChoosed xn in ListChoosed2)
        {
            Panel2_in.Controls.Add(new LiteralControl("<tr>"));

            Label SetLb = xn.Label;
            TextBox txtBox = xn.TextBox;

            Panel2_in.Controls.Add(new LiteralControl("<td>"));
            Panel2_in.Controls.Add(SetLb);
            Panel2_in.Controls.Add(new LiteralControl("</td>"));

            Panel2_in.Controls.Add(new LiteralControl("<td>"));
            Panel2_in.Controls.Add(txtBox);
            Panel2_in.Controls.Add(new LiteralControl("</td>"));

            Panel2_in.Controls.Add(new LiteralControl("</tr>"));
        }
        Panel2_in.Controls.Add(new LiteralControl("</table>"));
    }

    protected void btn_add2_Click(object sender, EventArgs e)
    {
        fieldset2.Visible = true;
        btn_add2.Visible = false;
    }
    protected void btn_capnhat2_Click(object sender, EventArgs e)
    {
        ListChoosed2.Clear();
        Panel2_in.Controls.Clear();

        IList<RadTreeNode> ListNode = RadTreeView2.GetAllNodes();

        int i = 0;
        foreach (RadTreeNode node in ListNode)
        {

            if (node.Nodes.Count == 0 && node.Checked == true)
            {
                TextBox newTb = new TextBox();
                newTb.ID = "tb_2_" + i.ToString();

                Label newLb = new Label();
                newLb.Text = node.Text;

                XNChoosed newXN = new XNChoosed();
                newXN.Label = newLb;
                newXN.TextBox = newTb;
                newXN.id_madanhmuc = Int32.Parse(node.Value);

                ListChoosed2.Add(newXN);
                i++;
            }
        }

        showListChoose2();
    }

    public List<XNChoosed> listXN1{
        get { return ListChoosed1; }
    }

    public List<XNChoosed> listXN2{
        get { return ListChoosed2; }
    }
    protected void btn_add1_Click(object sender, EventArgs e)
    {
        fieldset1.Visible = true;
        btn_add1.Visible = false;
        if(fieldset2.Visible == false)btn_add2.Visible = true;
    }
    protected void btn_dong1_Click(object sender, EventArgs e)
    {
        fieldset1.Visible = false;
        btn_add1.Visible = true;
        btn_add2.Visible = false;
        ListChoosed1.Clear();
    }
    protected void btn_dong2_Click(object sender, EventArgs e)
    {
        fieldset2.Visible = false;
        btn_add2.Visible = true;
        ListChoosed2.Clear();
    }
}
